package com.piggy.logi.sys.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.piggy.common.core.web.page.BaseMapperPlus;
import com.piggy.common.core.web.page.BaseMapperPlusEx;
import com.piggy.logi.sys.api.domain.LogiSysDictData;
import com.piggy.logi.sys.api.domain.LogiSysDictType;
import com.piggy.sys.api.domain.SysDictData;

import java.util.List;

/**
 * 字典表 数据层
 *
 * @author shark
 */
public interface LogiSysDictDataMapper extends BaseMapperPlusEx<LogiSysDictDataMapper, LogiSysDictData,LogiSysDictData> {

    default List<LogiSysDictData> selectDictDataByType(Long mainDeptId, String dictType) {
        return selectList(
                new LambdaQueryWrapper<LogiSysDictData>()
                        .eq(LogiSysDictData::getStatus, "0")
                        .eq(LogiSysDictData::getDictType, dictType)
                        .in(LogiSysDictData::getDeptId, 0L, ObjectUtil.defaultIfNull(mainDeptId,0L))
                        .notExists(ObjectUtil.isNotEmpty(mainDeptId) && mainDeptId > 0L,
                                " select dict_id from logi_sys_dict_type where dept_id=0 and dict_type in (select distinct dict_type from logi_sys_dict_type where dept_id={0}) ", mainDeptId)
                        .orderByAsc(LogiSysDictData::getDictSort));
    }
}
